package com.yuan.yblog.portal.schedules;

import com.yuan.yblog.portal.service.WeekRankService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Component
@Slf4j
public class rankTask {

    @Autowired
    WeekRankService weekRankService;

    /**
     * 更新周榜，每隔10min执行一次
     */
    @Scheduled(fixedDelay = 10, timeUnit = TimeUnit.MINUTES)
    public void rankUnion(){
        if(weekRankService.isNewest()) {
            // 周榜是最新的不需更新
            return;
        }
        weekRankService.rankUnion();
        log.info("文章周榜发生了更新~");
    }
}
